package com.sgb.contract.view.ui.openaccount;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;

import com.google.gson.Gson;
import com.sgb.contract.R;
import com.sgb.contract.base.BaseActivity;
import com.sgb.contract.databinding.ContractUseropenaccountinfoActivityBinding;
import com.sgb.contract.test.model.OpenAccountDetailEntity;
import com.sgb.contract.view.ui.accountdetail.AccountDetailViewModel;

/**
 * 作者:张磊
 * 日期:2022/1/4 0004
 * 说明:个人开通信息
 */
public class UserOpenAccountInfoActivity extends BaseActivity<ContractUseropenaccountinfoActivityBinding, AccountDetailViewModel> {

    private OpenAccountDetailEntity mDetailEntity;

    public static void start(Context context) {
        Intent intent = new Intent(context, UserOpenAccountInfoActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.contract_useropenaccountinfo_activity;
    }

    @Override
    protected void initViewModel() {
        mViewModel = createViewModel(AccountDetailViewModel.class, 0);
    }

    @Override
    protected void init() {
        mDataBinding.head.title.setText("在线合同开户信息");
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void initObserve() {
        mViewModel.detail.observe(this, data -> {
            mDetailEntity = data;
            mDataBinding.tvId.setText(data.csUserId);
            mDataBinding.tvPhoneNumber.setText(data.phone.substring(0, 3) + "****" + data.phone.substring(data.phone.length() - 4));
            mDataBinding.tvName.setText(data.name);
            mDataBinding.tvIdCard.setText(data.identityCard.substring(0, 4) + "**********" + data.identityCard.substring(data.identityCard.length() - 4));
        });
    }

    @Override
    protected void initListener() {
        mDataBinding.tvBtn.setOnClickListener(v -> {
            if (mDetailEntity==null)return;
            AlterInfoActivity.start(this, mDataBinding.tvPhoneNumber.getText().toString(),new Gson().toJson(mDetailEntity));
        });
        mDataBinding.head.ivBack.setOnClickListener(v -> finish());
    }


    @Override
    protected void onResume() {
        super.onResume();
        mViewModel.getCompanyDetail(this);
    }
}